
<?php
//print_r($page);
//print_r($vars['page_type']);

elgg_load_library('elgg:portfolio');

$trade_date = get_input('date');
$portfolio_id = get_input('portfolio');
$security_code = get_input('sec');
$usr_id = elgg_get_logged_in_user_guid();

//$today = strftime('%Y-%m-%d', time());
//$comment_closed = ($today>$trade_date);
$comment_closed = check_comment_closed($trade_date);

$vars = array();
portfolio_get_trade_summary($trade_date, $portfolio_id, $security_code, $vars);
portfolio_get_trade_review($trade_date, $portfolio_id, $security_code, $vars);

$blogpicker_input = elgg_view("input/blogpicker", array(
	  'form_id' => 'trade_comments',
		'name' => 'blogs',
		'value' => $vars['BlogLink'],  //blog id array
		'readonly' => $comment_closed, 
	));
	
$action_url = elgg_get_site_url()."action/trade/comments";
?>

<style type="text/css">
#trade_comments fieldset {
padding:10px;
margin-top:5px;
border:1px solid #1E7ACE;
background:#fff;
} 
#trade_comments fieldset legend {
color:#1E7ACE;
font-weight:bold;
padding:3px 3px 3px 3px;
background:#fff;
} 
#trade_comments table {
}
#trade_comments table td {
padding:5px;
}
#trade_comments .trade_summary {
width:360px;
}
#trade_comments .trade_summary td {
padding:2px;
}
#trade_comments .trade_summary td.value {
color:#808080;
}
#trade_comments label {
font-size:100%;
font-weight:normal;
}
</style>

<form id='trade_comments' method='post' action='<?php echo $action_url; ?>'>
<?php if (!$vars['disable_security']) { echo elgg_view('input/securitytoken'); } ?>
	<table>
		<tr>
			<td>
	<fieldset style='height:160px;'>
		<legend>交易总结</legend>
		<table class='trade_summary'>
			<tr>
				<td>交易日</td>
				<td class='value'><?php echo $vars['Date']; ?></td>
				<td>买卖</td>
				<td class='value'><?php echo $vars['B/S']; ?></td>
			</tr>
			<tr>
				<td>证券代码</td>
				<td class='value'><?php echo $vars['Ticker']; ?></td>
				<td>证券名称</td>
				<td class='value'><?php echo $vars['Name']; ?></td>
			</tr>
			<tr>
				<td>基金代码</td>
				<td class='value'><?php echo $vars['FundID']; ?></td>
				<td>基金名称</td>
				<td class='value'><?php echo $vars['Fund']; ?></td>
			</tr>
			<tr><td></td><td></td><td></td><td></td></tr>
			<tr>
				<td>前持仓</td>
				<td class='value'><?php echo number_format($vars['PreHld'],0); ?></td>
				<td>今日交易</td>
				<td class='value'><?php echo number_format($vars['ExeAmt'],0); ?></td>
			</tr>
			<tr>
				<td>前成本</td>
				<td class='value'><?php echo number_format($vars['PreAvgCost'],2); ?></td>
				<td>成交价格</td>
				<td class='value'><?php echo number_format($vars['ExePirce'],2); ?></td>
			</tr>
			<tr>
				<td>前仓位 (%)</td>
				<td class='value'><?php echo number_format($vars['PreWeight'],2); ?></td>
				<td>仓位增减 (%)</td>
				<td class='value'><?php echo number_format($vars['WeightChg'],2); ?></td>
			</tr>
		</table>
	</fieldset>
			</td>
			<td>
	<fieldset style='height:160px; width:120px;'>
		<legend>买入</legend>
		<?php 
		
		echo elgg_view('input/radio', array(
			'name' => 'buysell',
			'options' => array_flip(get_trade_reason_options_array('B')),
			'value' => $vars['Reason'],
			'disabled' => ($vars["B/S"] == 'S') || $comment_closed,
		));
		?>
	</fieldset>
			</td>
			<td>
	<fieldset style='height:160px; width:120px;'>
		<legend>卖出</legend>
		<?php 
		
		echo elgg_view('input/radio', array(
			'name' => 'buysell',
			'options' => array_flip(get_trade_reason_options_array('S')), 
			'value' => $vars['Reason'],
			'disabled' => ($vars["B/S"] == 'B') || $comment_closed,
		));
		?>
	</fieldset>
			</td>
		</tr>
		<tr>
			<td>
	<fieldset>
		<legend>说明</legend>
	<?php
	echo elgg_view('input/plaintext', array(
		'name' => 'remark',
		'value' => $vars['Remark'],
		'style' => 'width:360px;height:100px;border:0px;font-size:12px;',
		'disabled' => $comment_closed,
	));
	?>
	</fieldset>
			</td>
			<td colspan='2'>
	<fieldset style=''>
		<legend>前瞻</legend>
		<?php 
		echo elgg_view('input/radio', array(
			'name' => 'forsee',
			'options' => array_flip(get_trade_predict_horizon_options_array()),
			'value' => $vars['PredictHorizon'],
			'align' => 'horizontal',
			'disabled' => ($vars["B/S"] == 'S') || $comment_closed,
		));
		?>
	</fieldset>
			</td>
		</tr>
		<tr>
			<td>
	<?php
	echo $blogpicker_input;
	?>
			</td>
			<td></td>
			<td style='text-align:right;'>
	<?php
	echo elgg_view('input/submit', array(
		'value' => 'Save',
		'disabled' => $comment_closed,
	));
	if ($vars['page_type'] == 'lightbox') {
		$onclick = '$("#fancybox-close").trigger("click");';
	} else {
		$onclick = 'javascript:window.close();';
	}
	echo elgg_view('input/button', array(
		'value' => 'Cancel',
		'onclick' => $onclick,
	));

	echo elgg_view('input/hidden', array(
		'name' => 'date',
		'value' => $trade_date,
	));
	echo elgg_view('input/hidden', array(
		'name' => 'portfolio',
		'value' => $portfolio_id,
	));
	echo elgg_view('input/hidden', array(
		'name' => 'sec',
		'value' => $security_code,
	));		
	
	?>
			</td>
		</tr>
	</table>
	
</form>